<template>
  <div class="content content2">
    <div class="header">
      <div class="title" style="display:flex;justify-content: space-between;width: 100%;align-items: center;">
        <span>人效排名（月度）</span>
        <el-select v-model="id" placeholder="请选择" style="width:88px;height:32px;" @change="seleFn">
          <el-option v-for="item in options" :key="item.value" :label="item.name" :value="item.id" />
        </el-select>
      </div>
      <div class="week-month-year">
        <div
          v-for="(item, index) in isRepair"
          :key="index"
          class="item"
          :class="{ active: selDate === item.isRepair }"
          @click="selDateFn(item.isRepair)"
        >{{ item.name }}
        </div>
      </div>
      <div style="margin-top:20px">
        <el-row v-for="(item, index) in rankList" :key="index" class="item">
          <el-col :span="5">{{ index + 1 }}</el-col>
          <el-col :span="13">{{ item.userName }}</el-col>
          <el-col :span="6">{{ item.workCount }}单</el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { regionSearch, userWorkTop10 } from '@/api'
import { parseTime } from '@/utils'
export default {
  data() {
    return {
      options: [],
      id: 0,
      selDate: false,
      isRepair: [
        {
          name: '运营人员',
          isRepair: false
        },
        {
          name: '运维人员',
          isRepair: true
        }
      ],
      rankList: []
    }
  },
  async created() {
    const res = await regionSearch({
      pageIndex: 1,
      pageSize: 1000
    })
    this.options = [{ name: '全部', id: 0 }, ...res.data.currentPageRecords]
    const res1 = await this.userWorkTop10Api('false', this.id)
    this.rankList = res1.data
  },
  methods: {
    async userWorkTop10Api(isRepair, regionId) {
      const res = await userWorkTop10(
        parseTime(new Date(), `{y}-${(new Date()).getMonth() + 1}-01`),
        parseTime(new Date(), '{y}-{m}-{d}'),
        isRepair, regionId)
      return res
    },
    async selDateFn(item) {
      this.selDate = item
      // console.log(item)
      // if (item === '运营人员') {
      const res1 = await this.userWorkTop10Api(item, this.id)
      this.rankList = res1.data
      // } else {
      //   const res1 = await this.userWorkTop10Api('true', this.id)
      //   this.rankList = res1.data
      // }
    },
    async seleFn() {
      console.log(this.id)
      const res1 = await this.userWorkTop10Api(this.selDate, this.id)
      this.rankList = res1.data
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/count.scss";
// @import "~@/styles/hot-product.scss";

.content2 {
  background-color: #fff !important;
  background-image: none !important;
  min-height: 542px;
}

::v-deep .el-input__inner {
  height: 32px;
}

::v-deep .el-input__icon {
  line-height: 32px !important;
}

.week-month-year {
  display: flex;
  width: 129px;
  height: 34px;
  background: rgba(233, 243, 255, .37);
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  width: 177px;
  margin: 15px auto 0;

  .item {
    flex: 1;
    text-align: center;
    width: 37px;
    line-height: 25px;
    height: 25px;
    font-size: 14px;
    color: #9ca3b4;
    cursor: pointer;
  }
}

.active {
  box-shadow: 0 0 4px 0 rgb(0 0 0 / 11%);
  border-radius: 7px;
  font-weight: 600;
  color: #333 !important;
  background: #fff;
}

.el-row {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  line-height: 20px;

  .el-col-6 {
    text-align: right;
  }
}
</style>
